﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
using FS.Business;
using FS.Common.DotNetCode;
using FS.Common.DotNetUI;
using FS.Web.UserControl;

namespace FS.Web.BLL.Visa_Base
{
    public partial class Visa_InfoLine : System.Web.UI.Page
    {
        visa_dao _visa = new visa_dao();
        protected void Page_Load(object sender, EventArgs e)
        {
            this.PageControl1.pageHandler += new EventHandler(this.pager_PageChanged);
            if (!base.IsPostBack)
            {
              GetSelect_TrustInfo();
              //GetSelect_InfoFlag();
              GetSelect_City();
              //GetSelect_Operation();
              //GetSelect_Certtype();
              //GetSelect_Dataintegrity();
            }
        }
        #region 初始项目数据绑定
        //委托方
        private void GetSelect_TrustInfo()
        {
          DataTable dt = _visa.GetSelect_TrustInfo();
          ControlBindHelper.BindHtmlSelect(dt, this.sel_trust, "trust_name", "trust_id", "请选择");
        }

        //签证状态
        private void GetSelect_InfoFlag()
        {
          DataTable dt = _visa.GetSelect_InfoFlag();
          ControlBindHelper.BindHtmlSelect(dt, this.sel_infoflag, "property_value", "property_key", "请选择");
        }

        //所属国家
        private void GetSelect_City()
        {
          DataTable dt = _visa.GetSelect_CityInfo();
          ControlBindHelper.BindHtmlSelect(dt, this.sel_cityid, "city_name", "city_id", "请选择");
        }
        //经办人
        //private void GetSelect_Operation()
        //{
        //  DataTable dt = this._sys_idao.GetSelect_CurrentUserList();
        //  ControlBindHelper.BindHtmlSelect(dt, this.sel_operation, "user_name", "user_id", "请选择");
        //}
        //签证类型
        private void GetSelect_Certtype()
        {
          DataTable dt = _visa.GetSelect_CertType();
          ControlBindHelper.BindHtmlSelect(dt, this.sel_certtype, "property_value", "property_id", "请选择");
        }

        //资料齐全
        //public void GetSelect_Dataintegrity()
        //{
        //  DataTable dt = _visa.GetSelect_Dataintegrity();
        //  ControlBindHelper.BindHtmlSelect(dt, this.sel_datainterity, "property_value", "property_key", "请选择");
        //}
        #endregion


        protected void pager_PageChanged(object sender, EventArgs e)
        {
            this.DataBindGrid();
        }
             
        protected void lbtSearch_Click(object sender, EventArgs e)
        {
          this.Hchange.Value = "1";  
          DataBindGrid();
        }

        private void DataBindGrid()
        {
          int count = 0;
          if (this.Hchange.Value == "1")
          {
            this.PageControl1.PageIndex = 1;
            this.Hchange.Value = "0";
          }
          StringBuilder SqlWhere = new StringBuilder();
          IList<SqlParam> IList_param = new List<SqlParam>();
          if (!string.IsNullOrEmpty(this.sel_trust.Value))
          {
              SqlWhere.Append(" and visa_info.trust_id ='" + this.sel_trust.Value.Trim() + "'");
            //IList_param.Add(new SqlParam("@trust_id", this.sel_trust.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.sel_cityid.Value))
          {
              SqlWhere.Append(" and Visa_InfoDetail.City_id ='" + this.sel_cityid.Value.Trim() + "'");
            //IList_param.Add(new SqlParam("@City_id", this.sel_cityid.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.sel_certtype.Value))
          {
              SqlWhere.Append(" and Visa_InfoDetail.Ref_CertType ='" + this.sel_certtype.Value.Trim() + "'");
            //IList_param.Add(new SqlParam("@ref_certtype", this.sel_certtype.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.info_getdate.Value))
          {
              SqlWhere.Append(" and Visa_Info.[info_getdate] ='" + this.info_getdate.Value.Trim() + "'");
            //IList_param.Add(new SqlParam("@info_getdate", this.info_getdate.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.sel_datainterity.Value))
          {
              SqlWhere.Append(" and [Data_integrity] =" + this.sel_datainterity.Value);
            //IList_param.Add(new SqlParam("@Data_integrity", this.sel_datainterity.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.InfoDetail_user.Value))
          {
              SqlWhere.Append(" and [InfoDetail_user] = '" + this.InfoDetail_user.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_user", this.InfoDetail_user.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.InfoDetail_userphone.Value))
          {
              SqlWhere.Append(" and [InfoDetail_userphone] = '" + this.InfoDetail_userphone.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_userphone", this.InfoDetail_userphone.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.InfoDetail_Submitdate.Value))
          {
              SqlWhere.Append(" and [InfoDetail_Submitdate] = '" + this.InfoDetail_Submitdate.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_Submitdate", this.InfoDetail_Submitdate.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.InfoDetail_cardno.Value))
          {
              SqlWhere.Append(" and [InfoDetail_cardno] = '" + this.InfoDetail_cardno.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_cardno", this.InfoDetail_cardno.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.sel_operation.Value))
          {
              SqlWhere.Append(" and [InfoDetail_operationname] = '" + this.sel_operation.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_operationid", this.sel_operation.Value.Trim()));
          }
          if (!string.IsNullOrEmpty(this.sel_infoflag.Value))
          {
              SqlWhere.Append(" and Visa_Info.Ref_infoflag ='" + this.sel_infoflag.Value + "'");
            //IList_param.Add(new SqlParam("@Ref_infoflag", this.sel_infoflag.Value.Trim()));
          } 
          if (!string.IsNullOrEmpty(this.InfoDetail_Receivedate.Value))
          {
              SqlWhere.Append(" and [InfoDetail_Receivedate] = '" + this.InfoDetail_Receivedate.Value + "'");
            //IList_param.Add(new SqlParam("@InfoDetail_Receivedate", this.InfoDetail_Receivedate.Value.Trim()));
          }          
          if (!string.IsNullOrEmpty(this.info_no.Value))
          {
              SqlWhere.Append(" and [Info_ID] = '" + this.info_no.Value + "'");
            //IList_param.Add(new SqlParam("@info_no", this.info_no.Value.Trim()));
          }

          DataTable dt = this._visa.GetVisaInfoDetailPage(SqlWhere, IList_param, this.PageControl1.PageIndex, this.PageControl1.PageSize, ref count);

          for (int i = 0; i < dt.Rows.Count; i++)
          {
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "sendto")
              {
                  dt.Rows[i][5] = "送签";
              }
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "post")
              {
                  dt.Rows[i][5] = "寄件";
              }
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "audit")
              {
                  dt.Rows[i][5] = "审核";
              }
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "resultok")
              {
                  dt.Rows[i][5] = "出签";
              }
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "resultfalse")
              {
                  dt.Rows[i][5] = "拒签";
              }
              if (dt.Rows[i][5].ToString().ToLower().Trim() == "raise")
              {
                  dt.Rows[i][5] = "录证";
              }
              if (dt.Rows[i][7].ToString().Trim() == "1a")
              {
                  dt.Rows[i][7] = "是";
              }
              else
              {
                  dt.Rows[i][7] = "否";
              }
          }
            ControlBindHelper.BindRepeaterList(dt, this.rp_Item);
          this.PageControl1.SetPageCount(count);
        }
        protected void lbtExport_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/vnd.ms-excel.numberformat:@";
            this.EnableViewState = false;
            Response.Charset = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xls");
            Response.Write(printHid.Value);
            Response.End();
        }
    }
}